package ooday04;


/*1. 设计Animal类、Swim接口、Dog类、Fish类、Chick类，完成继承和实现关系，创建数组并测试
 */
//设计捕食系统,高等级动物可以捕食低等级动物
//设计繁殖系统,在适龄范围内的雌性动物,可生产性别随机的0岁孩子
public class Test {
    public static void main(String[] args) {
        Master master = new Master();
        Dog dog = new Dog("小白", 2, "白", "female");
        Fish fish = new Fish("小金", 1, "金", "female");
        Tiger tiger = new Tiger("大花", 4, "花", "male");
        master.feed(dog); //在传参的同时，系统自动做了向上造型
        master.feed(fish);
        master.feed(tiger);
        System.out.println("=====================");
        Animal[] animals = new Animal[4];
        animals[0] = new Dog("黑子", 2, "黑", "female");
        animals[1] = new Fish("金子", 1, "金", "male");
        animals[2] = new Tiger("花花", 5, "白", "female");
        animals[3] = new Chick("小花", 2, "灰", "male");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].getName());
            animals[i].eat();
            animals[i].drink();

            if (animals[i] instanceof Dog) {
                ((Dog) animals[i]).lookHome();
            }
            if (animals[i] instanceof Chick) {
                ((Chick) animals[i]).layEggs();
            }
            if (animals[i] instanceof Swim) {
                Swim s = (Swim) animals[i];
                s.swim();
            }
        }
        System.out.println("=====================");

        Animal o = new Dog("大黄",2,"黄","female");
        Dog d = (Dog)o;
        Swim s = (Swim)o;

        System.out.println(o instanceof Dog);
        System.out.println(o instanceof Swim);
        System.out.println(o instanceof Fish);
    }
}
